package edu.stanford.bmir.protege.web.client.ui.ontology.stkos.mapper.statistical;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.Label;

import edu.stanford.bmir.protege.web.client.project.Project;
import edu.stanford.bmir.protege.web.client.rpc.stkosutil.mapper.MappingResult;

public class StkosMapperStatisticalView extends Composite implements HasEnabled {

	interface StkosMapperStatisticalViewUiBinder extends
			UiBinder<HTMLPanel, StkosMapperStatisticalView> {
	}

	private static StkosMapperStatisticalViewUiBinder ourUiBinder = GWT
			.create(StkosMapperStatisticalViewUiBinder.class);

	private Project project;

	private MappingResult mappingResult;

	/** 当前工程 **/

	// 类总数
	@UiField
	protected Label currentProject_classCount;

	// 匹配类个数
	@UiField
	protected Label currentProject_matchClassNumber;

	// 属性总数
	@UiField
	protected Label currentProject_propertyCount;

	// 匹配属性个数
	@UiField
	protected Label currentProject_matchPropertyNumber;

	/** 参照工程 **/

	// 类总数
	@UiField
	protected Label accordingProject_classCount;

	// 匹配类个数
	@UiField
	protected Label accordingProject_matchClassNumber;

	// 属性总数
	@UiField
	protected Label accordingProject_propertyCount;

	// 匹配属性个数
	@UiField
	protected Label accordingProject_matchPropertyNumber;

	public StkosMapperStatisticalView(Project project) {
		this.project = project;

		HTMLPanel rootElement = ourUiBinder.createAndBindUi(this);
		initWidget(rootElement);
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public void setEnabled(boolean enabled) {
	}

	public void setMappingResult(MappingResult mappingResult) {
		this.mappingResult = mappingResult;

		int current_classCount = 0, current_matchClassNumber = 0, current_propertyCount = 0, current_matchPropertyNumber = 0;
		int according_classCount = 0, according_matchClassNumber = 0, according_propertyCount = 0, according_matchPropertyNumber = 0;

		if (mappingResult != null) {
			current_classCount = mappingResult.getO1ClassNumber();
			current_matchClassNumber = mappingResult.getO1MappedClassNumber();
			current_propertyCount = mappingResult.getO1PropertyNumber();
			current_matchPropertyNumber = mappingResult
					.getO1MappedPropertyNumber();

			according_classCount = mappingResult.getO2ClassNumber();
			according_matchClassNumber = mappingResult.getO2MappedClassNumber();
			according_propertyCount = mappingResult.getO2PropertyNumber();
			according_matchPropertyNumber = mappingResult
					.getO2MappedPropertyNumber();
		}

		currentProject_classCount.setText(String.valueOf(current_classCount));
		currentProject_matchClassNumber.setText(String
				.valueOf(current_matchClassNumber));
		currentProject_propertyCount.setText(String
				.valueOf(current_propertyCount));
		currentProject_matchPropertyNumber.setText(String
				.valueOf(current_matchPropertyNumber));

		accordingProject_classCount.setText(String
				.valueOf(according_classCount));
		accordingProject_matchClassNumber.setText(String
				.valueOf(according_matchClassNumber));
		accordingProject_propertyCount.setText(String
				.valueOf(according_propertyCount));
		accordingProject_matchPropertyNumber.setText(String
				.valueOf(according_matchPropertyNumber));
	}
}
